﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Brain
{
    /// <summary>
    /// Class used to generate a Checker Texture, procedurally generated
    /// </summary>
    public class ProceduralChecker : Texture2D
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="size">The size of the Texture(the Width and Height)</param>
        /// <param name="tile"></param>
        public ProceduralChecker(int size, int tile, Color tile1, Color tile2)
            : base(Engine.Instance.GraphicsDevice, size, size)
        {
            int checks = tile * 2;
            int CheckerSize = size / checks;

            Color[] colors = new Color[size * size];
            int made = 0;
            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    int realX = x / CheckerSize;
                    int realY = y / CheckerSize;
                    Color color;
                    if (realX % 2 == 0)
                    {
                        if (realY % 2 == 0)
                        {
                            color = tile1;
                        }
                        else
                        {
                            color = tile2;
                        }
                    }
                    else
                    {
                        if (realY % 2 == 0)
                        {
                            color = tile2;
                        }
                        else
                        {
                            color = tile1;
                        }
                    }
                    colors[made] = color;
                    made++;
                }
            }

            this.SetData<Color>(colors);
        }
    }
}
